#include <stdio.h>
#include <unistd.h>

#define FILE_NAME "log.txt"

int main()
{
  FILE* fp = fopen(FILE_NAME,"w");
  if(NULL == fp)
  {
    perror("fopen");
    return 1;
  }
  int cnt = 5;
  while(cnt)
  {
    fprintf(fp,"%s:%d\n","hello bit",cnt--);
  }

  // 关闭文件
  fclose(fp);
}
